package com.lly.bigdata.bgayx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lly.bigdata.bgayx.common.constants.em.CommonEnum;
import com.lly.bigdata.bgayx.common.utils.Pinyin4jUtils;
import com.lly.bigdata.bgayx.common.utils.StringUtils;
import com.lly.bigdata.bgayx.entity.SysMenu;
import com.lly.bigdata.bgayx.entity.SysMenuPinyin;
import com.lly.bigdata.bgayx.mapper.SysMenuPinyinMapper;
import com.lly.bigdata.bgayx.service.ISysMenuPinyinService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lly
 * @since 2020-10-21
 */
@Service
public class SysMenuPinyinServiceImpl extends ServiceImpl<SysMenuPinyinMapper, SysMenuPinyin> implements ISysMenuPinyinService {

    @Override
    public void addPinyin(SysMenu jkfwMenu) {
        String qypy = Pinyin4jUtils.getPinyinToLowerCase(jkfwMenu.getName());
        String jp = Pinyin4jUtils.getPinyinJianPinToLowerCase(jkfwMenu.getName());
        List<String> qypys = StringUtils.splitList(qypy);
        List<String> jpys = StringUtils.splitList(jp);
        for (String py : qypys) {
            SysMenuPinyin pinyin = new SysMenuPinyin();
            pinyin.setId(UUID.randomUUID().toString().replace("-", ""));
            pinyin.setMenuid(jkfwMenu.getId());
            pinyin.setPyzm(py);
            pinyin.setPyzmjx(CommonEnum.PinYinEnum.quanpin.getName());
            baseMapper.insert(pinyin);
        }
        for (String py : jpys) {
            SysMenuPinyin pinyin = new SysMenuPinyin();
            pinyin.setId(UUID.randomUUID().toString().replace("-", ""));
            pinyin.setMenuid(jkfwMenu.getId());
            pinyin.setPyzm(py);
            pinyin.setPyzmjx(CommonEnum.PinYinEnum.jianpin.getName());
            baseMapper.insert(pinyin);
        }
    }

    @Override
    public void delMenuid(String id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("menuid", id);
        baseMapper.delete(queryWrapper);
    }
}
